package cn.stylefeng.guns.modular.tool.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.tool.entity.ToolExpressReconciliationSfkhInstall;
import cn.stylefeng.guns.modular.tool.mapper.ToolExpressReconciliationSfkhInstallMapper;
import cn.stylefeng.guns.modular.tool.model.params.ToolExpressReconciliationSfkhInstallParam;
import cn.stylefeng.guns.modular.tool.model.result.ToolExpressReconciliationSfkhInstallResult;
import  cn.stylefeng.guns.modular.tool.service.ToolExpressReconciliationSfkhInstallService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 顺丰卡航报价设置 服务实现类
 * </p>
 *
 * @author zhucx
 * @since 2023-07-22
 */
@Service
public class ToolExpressReconciliationSfkhInstallServiceImpl extends ServiceImpl<ToolExpressReconciliationSfkhInstallMapper, ToolExpressReconciliationSfkhInstall> implements ToolExpressReconciliationSfkhInstallService {

    @Override
    public void add(ToolExpressReconciliationSfkhInstallParam param){
        ToolExpressReconciliationSfkhInstall entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ToolExpressReconciliationSfkhInstallParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ToolExpressReconciliationSfkhInstallParam param){
        ToolExpressReconciliationSfkhInstall oldEntity = getOldEntity(param);
        ToolExpressReconciliationSfkhInstall newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ToolExpressReconciliationSfkhInstallResult findBySpec(ToolExpressReconciliationSfkhInstallParam param){
        return null;
    }

    @Override
    public List<ToolExpressReconciliationSfkhInstallResult> findListBySpec(ToolExpressReconciliationSfkhInstallParam param,Long operateId){
        return this.baseMapper.findListBySpec(param,operateId);
    }

    @Override
    public LayuiPageInfo findPageBySpec(ToolExpressReconciliationSfkhInstallParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ToolExpressReconciliationSfkhInstallParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ToolExpressReconciliationSfkhInstall getOldEntity(ToolExpressReconciliationSfkhInstallParam param) {
        return this.getById(getKey(param));
    }

    private ToolExpressReconciliationSfkhInstall getEntity(ToolExpressReconciliationSfkhInstallParam param) {
        ToolExpressReconciliationSfkhInstall entity = new ToolExpressReconciliationSfkhInstall();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
